<?php
session_start();
if (isset($_SESSION["username"])) {
?>
    <?php require_once('common/header.php'); ?>
    <!--页面主要内容-->
    <main class="lyear-layout-content">
        <div class="container-fluid">

            <?php
            include_once("../untils/conn.php");
            $id = $_GET['id'];
            $data = mysqli_query($con, "select * from list where id=" . $id);
            $rows = mysqli_fetch_row($data);
            ?>
            <div class="card">
                <div class="card-header bg-primary">
                    <h4>更新产品</h4>
                </div>
                <div class="card-body">
                    <form class="form-horizontal" action="controller/doUpdate.php" method="POST">
                        <div class="form-group">
                            <label for="title" class="col-xs-12">名称：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="name" placeholder="请输入产品名称" value="<?php echo $rows[2] ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">提单接口：</label>
                            <div class="col-xs-12">
                             <select class="form-control" id="provider" onchange="toggleInput()" name="api_type">
                                <?php
                                $apiType = $rows[21]; // 从数据库中获取api_type的值
                                $options = array(
                                    "yqrapi" => "172系统",
                                    "yidong" => "移动",
                                    "hnhklt" => "海南联通",
                                    "zgdx" => "电信",
                                    "gantanhao" => "感探号",
                                    "haokeyun" => "号氪云"
                                );
                                foreach ($options as $value => $label) {
                                    $selected = ($apiType == $value) ? "selected" : "";
                                    echo "<option value=\"$value\" $selected>$label</option>";
                                }
                                ?>
                            </select>
                            </div>
                        </div>
                        <div class="form-group" id="haokaidGroup" style="display: none;" >
                            <label for="title" class="col-xs-12">172商品id：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="yqrid" placeholder="没有请填写0" value="<?php echo $rows[1] ?>" >
                            </div>
                        </div>
                        <div class="form-group" id="ltGroup" style="display: none;" >
                            <label class="col-xs-12">联通产品类型：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="productType" placeholder="联通产品类型ID" value="<?php echo $rows[1] ?>" >
                            </div>
                        </div>
                        <div class="form-group" id="haoke" style="display: none;" >
                            <label class="col-xs-12">号氪云产品编码：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="goodsCode" placeholder="号氪云产品编码" value="<?php echo $rows[1] ?>" >
                            </div>
                        </div>
                        <div class="form-group" id="gantan" style="display: none;" >
                            <label class="col-xs-12">感叹号产品编号：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="sku" placeholder="感叹号产品编号" value="<?php echo $rows[1] ?>">
                            </div>
                        </div>
                        <div class="form-group" id="xhGroup" style="display: none;">
                            <label class="col-xs-12">是否支持选号：</label>
                            <div class="col-xs-12">
                                <select class="form-control" name="se_num">
                                    <?php
                                    $seNum = $rows[22]; // 从数据库中获取se_num的值
                                    $options = array(
                                        "0" => "不支持",
                                        "1" => "支持"
                                    );
                                    foreach ($options as $value => $label) {
                                        $selected = ($seNum == $value) ? "selected" : "";
                                        echo "<option value=\"$value\" $selected>$label</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        
                         <div class="form-group">
                            <label class="col-xs-12">下单模版：</label>
                            <div class="col-xs-12">
                             <select class="form-control"  name = "downtel">
                              <?php
                                    $downtel = $rows[23]; // 从数据库中获取downtel的值
                                    $options = array(
                                        "one" => "默认模板-系统平台模版",
                                        "two" => "蓝色互动模版-不支持选号"
                                    );
                                    foreach ($options as $value => $label) {
                                        $selected = ($downtel == $value) ? "selected" : "";
                                        echo "<option value=\"$value\" $selected>$label</option>";
                                    }
                                    ?>
                            </select>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="title" class="col-xs-12">介绍：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="jieshao" placeholder="请输入产品简短介绍" value="<?php echo $rows[3] ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-xs-12">时长：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="ltime" placeholder="套餐时长,建议四个字" value="<?php echo $rows[5] ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">运营商：</label>
                            <div class="col-xs-12">
                                <?php
                                include_once("../untils/conn.php");
                                mysqli_query($con, "set names utf8");
                                if ($con) {
                                    //选择数据库
                                    if ($db) {
                                        //获取数据总行数
                                        $sortsql = "select * from sort";
                                        $sortdata = mysqli_query($con, $sortsql);
                                ?>
                                        <select name="yys" id="yys" class="form-control">
                                            <?php
                                            while ($sortrow = mysqli_fetch_array($sortdata)) {
                                            ?>
                                                <option value="<?php echo $sortrow["yys"] ?>" name="yys" <?php echo $rows[5] == $sortrow["yys"]  ? 'selected' : '' ?>><?php echo $sortrow["yys"] ?></option>
                                            <?php
                                            }

                                            ?>
                                        </select>
                                <?php
                                    }
                                }

                                ?>
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">限龄：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="other" placeholder="可以写限龄，或其他，用于显示前台，可为空" value="<?php echo $rows[11] ?>" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-xs-12">归属地：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="gsd" placeholder="请输入号卡归属地" value="<?php echo $rows[9] ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-xs-12">商品标签：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="xuanhao" placeholder="请输入选号方式（激活选号/选号下单/随机号码）" value="<?php echo $rows[10] ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-xs-12">快递方式：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="baoyou" placeholder="可输入全国免费包邮/京东物流等" value="<?php echo $rows[12] ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-xs-12">主图链接：</label>
                            <div class="col-xs-12">
                                <input type="url" class="form-control" name="zhutu" placeholder="主图URL地址" value="<?php echo $rows[4] ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-xs-12">详情图链接：</label>
                            <div class="col-xs-12">
                                <input type="url" class="form-control" name="link" value="<?php echo $rows[8] ?>" placeholder="请输入详情图链接" required>
                            </div>
                        </div>
                          <div class="form-group">
                            <label class="col-xs-12">商品真实佣金（填写真实佣金用于数据计算）</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="price" value="<?php echo $rows[17] ?>" placeholder="商品佣金" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">代理佣金（用于结算代理的佣金，请用商品说明一致）</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="proxy_price" value="<?php echo $rows[19] ?>" placeholder="商品佣金" required>
                            </div>
                        </div>
                         <div class="form-group">
                            <label class="col-xs-12" for="notes">商品说明（代理看到的佣金说明）</label>
                            <div class="col-xs-12">
                              <textarea class="form-control"  name="notes"   placeholder="商品代理说明"><?php echo $rows[18] ?></textarea>
                            </div>
                          </div>
                        <div class="form-group">
                            <input type="hidden" name="id" value="<?php echo $id ?>">
                            <div class="offset-2 col-xs-12">
                                <button class="btn btn-success" type="submit" value="添加">确认修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        </div>
        </div>
        </div>
        </div>


        </div>
    </main>
        <script>
    window.onload = function() {
        toggleInput();
    };

    function toggleInput() {
        var provider = document.getElementById("provider").value;
        var haokaidGroup = document.getElementById("haokaidGroup");
        var ltGroup = document.getElementById("ltGroup");
        var xhGroup = document.getElementById("xhGroup");
        var haoke = document.getElementById("haoke");
        var gantan = document.getElementById("gantan");

        if (provider === "yqrapi") {
            haokaidGroup.style.display = "block";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "none";
            gantan.style.display = "none";
        } else if (provider === "hnhklt") {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "block";
            xhGroup.style.display = "block";
            haoke.style.display = "none";
            gantan.style.display = "none";
        } else if (provider === "haokeyun") {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "block";
            gantan.style.display = "none";
        } else if (provider === "gantanhao") {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "none";
            gantan.style.display = "block";
        } else {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "none";
            gantan.style.display = "none";
        }
    }
</script>
    <!--End 页面主要内容-->
    <?php require_once('common/footer.php'); ?>
<?php
} else {
    echo "<script>alert('您尚未登录，没有权限访问该页面');location.href='login.php';</script>";
}
